package com.hhh.springai_test.controller;

import com.hhh.springai_test.common.BaseResponse;
import com.hhh.springai_test.common.ResultUtils;
import com.hhh.springai_test.constant.UserConstant;
import com.hhh.springai_test.model.dto.aiPrompt.AiPromptAddRequest;
import com.hhh.springai_test.model.dto.aiPrompt.AiPromptUpdateRequest;
import com.hhh.springai_test.model.po.AiPrompt;
import com.hhh.springai_test.service.AiPromptService;
import cn.dev33.satoken.annotation.SaCheckRole;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/aiPrompt")
public class AiPromptController {

    @Resource
    private AiPromptService aiPromptService;

    /**
     * 创建
     *
     * @param aiPromptAddRequest
     * @return
     */
    @PostMapping("/add")
    @SaCheckRole(UserConstant.ADMIN_ROLE)
    public BaseResponse<Long> addAiPrompt(@RequestBody AiPromptAddRequest aiPromptAddRequest) {
        long result = aiPromptService.addAiPrompt(aiPromptAddRequest);
        return ResultUtils.success(result);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @PostMapping("/delete")
    @SaCheckRole(UserConstant.ADMIN_ROLE)
    public BaseResponse<Boolean> deleteAiPrompt(@RequestParam long id) {
        boolean result = aiPromptService.deleteAiPrompt(id);
        return ResultUtils.success(result);
    }

    /**
     * 更新
     *
     * @param aiPromptUpdateRequest
     * @return
     */
    @PostMapping("/update")
    @SaCheckRole(UserConstant.ADMIN_ROLE)
    public BaseResponse<Boolean> updateAiPrompt(@RequestBody AiPromptUpdateRequest aiPromptUpdateRequest) {
        boolean result = aiPromptService.updateAiPrompt(aiPromptUpdateRequest);
        return ResultUtils.success(result);
    }

    /**
     * 获取列表
     *
     * @return
     */
    @GetMapping("/list")
    public BaseResponse<List<AiPrompt>> listAiPrompt() {
        List<AiPrompt> aiPromptList = aiPromptService.listAiPrompt();
        return ResultUtils.success(aiPromptList);
    }
}
